/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.buzzwords.behaviors;

import com.buzzwords.model.Buzzword;
import com.buzzwords.model.User;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import javax.jdo.Query;

/**
 *
 * @author potlow
 */
public class UserUDIDBehavior extends UserBehavior {

    @Override
    public List<Object> read(Object value, List<String> properties) {

        String UDID;
        if (value instanceof String) {
            UDID = (String) value;
            if (UDID.isEmpty()) {
                throw new IllegalArgumentException("Search string cannot be empty");
            }
        } else {
            throw new IllegalArgumentException("Search value must be a String");
        }

        Query query = pm.newQuery(User.class);
        query.setFilter("UDID == UDIDParam");
        query.declareParameters("String UDIDParam");

        // get results
        try {
            List<Object> objects = (List<Object>) query.execute(UDID);
            List<Object> objectsToDetach = new ArrayList<Object>(objects);
            pm.detachCopyAll(objectsToDetach);
            return objects;
        } finally {
            query.closeAll();
        }
    }

    public List<Object> excute(String filter, String declareParameters,
            Map<String, Object> parameters, List<String> properties) {
        throw new UnsupportedOperationException("Not supported yet.");
    }
}
